package net.xumf.support.converter;

import net.xumf.domain.master.SystemModule;
import net.xumf.support.consts.Constants;
import net.xumf.support.model.vo.TreeAttributeVO;
import net.xumf.support.model.vo.TreeVO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * {@link List<SystemModule>} 转其他类型
 */
public class SystemModuleConverter {

    /**
     * {@link List<SystemModule>} 转 {@link List< TreeVO >}
     *
     * @param moduleList {@link List<SystemModule>}
     * @return {@link List< TreeVO >}
     */
    public static List<TreeVO> toModuleTreeVOList(final List<SystemModule> moduleList) {
        return moduleList.stream().map(o -> {
            TreeVO treeVO = new TreeVO();
            BeanUtils.copyProperties(o, treeVO);
            treeVO.setLabel(o.getName());
            treeVO.setLeaf(!o.getHasChild());
            return treeVO;
        }).collect(Collectors.toList());
    }
}
